<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    input {
      outline: none;
    }
  </style>
</head>

<body>
  <input type="text" id="txt" />
  <select name="" id="sel">
    <option value="0">广东</option>
    <option value="1">山西</option>
    <option value="2">河北</option>
  </select>
  <input type="checkbox" id="mycheck">
  <input type="text" id="myname">
  <script>
    // 表单事件
    var txt = document.getElementById("txt");
    txt.onfocus = function () { //1.onfocus 获取焦点事件
      console.log("获取焦点了")
      this.style.border = "1px solid red"
    }
    txt.onblur = function () { //2.失去焦点事件
      this.style.border = "1px solid green"
    }
    //3.onchange 表单元素改变事件  
    var sel = document.getElementById("sel");
    sel.onchange = function () {
      console.log(this.value)
    }
    var mycheck = document.getElementById("mycheck");
    mycheck.onchange = function () {
      console.log(this.checked)
      // console.log(this.getAttribute("checked"))
    }
    // 
    var myname = document.getElementById("myname")
    myname.onselect = function () { //输入框内部的文本被选择事件
      console.log("文本被选择了")
    }
  </script>
</body>

</html>